package com.kintreda.ieco_server.util.sms;


import com.kintreda.ieco_server.util.Parameters;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;

import javax.ws.rs.core.MediaType;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.api.web
 * @Author ZhongYao_H
 * @Date 2019/5/10:14:32
 * @Year 2019 Month 05 Day 10
 * @Date_zh 2019 年 五月 星期五
 */

public class SendMessage {

    /**
     * 发送短信
     *
     *
     * @param mobile  手机号
     * @param randm    随机数
     * @return
     */
    public static String SendMsg(String mobile,String randm){
        // just replace key here
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter(
                "api","key-"+ Parameters.MSGKEY));
        WebResource webResource = client.resource("http://sms-api.luosimao.com/v1/send.json");
        MultivaluedMapImpl formData = new MultivaluedMapImpl();
        formData.add("mobile", mobile);
        formData.add("message", "验证码："+randm+"【铁壳测试】");
        ClientResponse response =  webResource.type( MediaType.APPLICATION_FORM_URLENCODED ).
                post(ClientResponse.class, formData);
        String textEntity = response.getEntity(String.class);
        int status = response.getStatus();
        return textEntity;
    }


    /**
     *
     * 查询余额
     *
     *
     * @return
     */
    public static String queryStatus(){
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter(
                "api","key-"+ Parameters.MSGKEY));
        WebResource webResource = client.resource( "http://sms-api.luosimao.com/v1/status.json" );
        MultivaluedMapImpl formData = new MultivaluedMapImpl();
        ClientResponse response =  webResource.get( ClientResponse.class );
        String textEntity = response.getEntity(String.class);
        int status = response.getStatus();
        return textEntity;
    }
}
